<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../../../assets/libs/jquery/jquery-3.6.1.min.js"></script>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    html {
      height: 200vh;
      background-image: linear-gradient(black, white);
    }

    .container {
      position: relative;
      top: 100vh;
      left: 50%;
      transform: translateX(-50%);
      width: 500px;
      height: 500px;
      background-color: white;
    }

    .content {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 200px;
      height: 200px;
      background-color: rgba(17, 119, 255, 0.5);
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="content"></div>
  </div>

  <script>
    // 获取相对于第一个非 static 定位的父元素的位置
    const position = $('.content').position()
    console.log(
      position.top,
      position.left
    )
  </script>
</body>

</html>